import React, { Component } from 'react'
import LifeChild from './LifeChild'
import LifeSon from './LifeSon'

export default class LifeCom extends Component {
    constructor() {
        super()

        console.log('constructor')
    }
    state = {
        num: 1
    }

    addNum = () => {
        this.setState({
            num: Math.floor(Math.random() * 3)
        })

    }

    componentWillMount () {
        console.log('componentWillMount')
    }






    render () {
        console.log('  父组件 render')
        return (

            <>
                <div>LifeCom ------- {this.state.num}

                    <div>
                        <button onClick={this.addNum}> 点击</button>


                    </div>



                </div>

                <hr />
                {/* {
                    this.state.num === 0 ? ' 子组件卸载了' : <LifeSon num={this.state.num}></LifeSon>
                } */}


                <LifeChild></LifeChild>



            </>

        )
    }


    componentDidMount () {
        console.log('componentDidMount')
    }
    shouldComponentUpdate () {

        console.log('shouldComponentUpdate');
        return true  //  默认是 true
        // return false
    }

    componentWillUpdate () {
        console.log('componentWillUpdate')
    }

    componentDidUpdate () {
        console.log('componentDidUpdate')
    }






}
